package com.vip.educms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.vip.educms.entity.CrmBanner;
import com.vip.educms.mapper.CrmBannerMapper;
import com.vip.educms.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.cache.annotation.Cacheable;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author hvip
 * @since 2020-08-31
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {

    // 查询所有的banner
    // Cacheable  先查询缓存，如果缓存有，就不调用
     @Cacheable(value = "banner", key = "'selectIndexList'")
    @Override
    public List<CrmBanner> selectAllBanner() {

        // 根据id排序，显示排列后前2条记录
        QueryWrapper<CrmBanner> wrapper = new QueryWrapper<>();
        wrapper.orderByAsc("id");
        wrapper.last("limit 2"); // 拼接sql语句

        List<CrmBanner> banners = baseMapper.selectList(wrapper);
        return banners;
    }
}
